﻿using System;
using System.Collections.Generic;

namespace YJKExcelFormTool.DataDefine
{
	public class TableHead
	{
		public TableHead._Tag_HeadType HeadType
		{
			get
			{
				return this.m_TableHeadType;
			}
			set
			{
				this.m_TableHeadType = value;
			}
		}

		public TableSourceInfo TableSourceInfo
		{
			get
			{
				return this.m_TableSourceInfo;
			}
			set
			{
				this.m_TableSourceInfo = value;
			}
		}

		public int RowSize
		{
			get
			{
				return this.m_RowSize;
			}
			set
			{
				this.m_RowSize = value;
			}
		}

		public int ColumnSize
		{
			get
			{
				return this.m_ColumnSize;
			}
			set
			{
				this.m_ColumnSize = value;
			}
		}

		public List<TableHeadCell> TableHeadInfos
		{
			get
			{
				return this.m_TableHeadInfos;
			}
			set
			{
				this.m_TableHeadInfos = value;
			}
		}

		public TableHead()
		{
		}

		public TableHead(TableHead head)
		{
			this.m_TableHeadType = head.m_TableHeadType;
			this.m_TableSourceInfo = head.m_TableSourceInfo;
			this.m_TableHeadInfos = head.m_TableHeadInfos;
			this.m_RowSize = head.m_RowSize;
			this.m_ColumnSize = head.m_ColumnSize;
			this.m_RowHeightList = head.m_RowHeightList;
			this.m_ColWidthList = head.m_ColWidthList;
		}

		public TableHead(TableHead._Tag_HeadType tableHeadType, TableSourceInfo tableSourceInfo, List<TableHeadCell> tableHeadInfos, int rowSize, int columnSize, List<double> rowHeightList, List<double> colWidthList)
		{
			this.m_TableHeadType = tableHeadType;
			this.m_TableSourceInfo = tableSourceInfo;
			this.m_TableHeadInfos = tableHeadInfos;
			this.m_RowSize = rowSize;
			this.m_ColumnSize = columnSize;
			this.m_RowHeightList = rowHeightList;
			this.m_ColWidthList = colWidthList;
		}

		public bool IsNull()
		{
			return this.HeadType == TableHead._Tag_HeadType.HT_NULL;
		}

		public double CellHeight(TableHeadCell cell)
		{
			double num = 0.0;
			foreach (int index in cell.RowIndex)
			{
				num += this.RowHeightOfIndex(index);
			}
			return num;
		}

		public double CellWidth(TableHeadCell cell)
		{
			double num = 0.0;
			foreach (int index in cell.ColIndex)
			{
				num += this.ColWidthOfIndex(index);
			}
			return num;
		}

		public void CellPosition(TableHeadCell cell, ref double left, ref double top)
		{
			double num = 0.0;
			for (int i = 0; i < cell.ColIndex[0]; i++)
			{
				num += this.ColWidthOfIndex(i);
			}
			left = num;
			double num2 = 0.0;
			for (int i = 0; i < cell.RowIndex[0]; i++)
			{
				num2 += this.RowHeightOfIndex(i);
			}
			top = num2;
		}

		public void SetEffectiveRowItemWidthByIndex(int index, double width)
		{
			List<TableHeadCell> effectiveRow = this.GetEffectiveRow();
			if (index < 0 || index >= effectiveRow.Count)
			{
				return;
			}
			double num = width / this.CellWidth(effectiveRow[index]);
			for (int i = 0; i < effectiveRow[index].ColIndex.Count; i++)
			{
				int num2 = effectiveRow[index].ColIndex[i];
				List<double> colWidthList = this.m_ColWidthList;
				int index2 = num2;
				colWidthList[index2] *= num;
			}
		}

		public double GetEffectiveRowItemWidthByIndex(int index)
		{
			List<TableHeadCell> effectiveRow = this.GetEffectiveRow();
			if (index < 0 || index >= effectiveRow.Count)
			{
				return 0.0;
			}
			return this.CellWidth(effectiveRow[index]);
		}

		public List<TableHeadCell> GetEffectiveRow()
		{
			List<TableHeadCell> list = new List<TableHeadCell>();
			foreach (TableHeadCell tableHeadCell in this.m_TableHeadInfos)
			{
				bool flag = false;
				using (List<int>.Enumerator enumerator2 = tableHeadCell.RowIndex.GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						if (enumerator2.Current == this.RowSize - 1)
						{
							flag = true;
							break;
						}
					}
				}
				if (flag)
				{
					bool flag2 = false;
					for (int i = 0; i < list.Count; i++)
					{
						if (list[i].ColIndex[0] > tableHeadCell.ColIndex[0])
						{
							list.Insert(i, tableHeadCell);
							flag2 = true;
							break;
						}
					}
					if (!flag2)
					{
						list.Add(tableHeadCell);
					}
				}
			}
			return list;
		}

		public List<double> GetCellHeightList()
		{
			List<double> list = new List<double>();
			foreach (double item in this.m_RowHeightList)
			{
				list.Add(item);
			}
			return list;
		}

		public void SetCellHeightList(List<double> rowHeightList)
		{
			this.m_RowHeightList.Clear();
			foreach (double item in rowHeightList)
			{
				this.m_RowHeightList.Add(item);
			}
		}

		public List<double> GetCellWidthList()
		{
			List<double> list = new List<double>();
			foreach (double item in this.m_ColWidthList)
			{
				list.Add(item);
			}
			return list;
		}

		public void SetCellWidthList(List<double> colWidthList)
		{
			this.m_ColWidthList.Clear();
			foreach (double item in colWidthList)
			{
				this.m_ColWidthList.Add(item);
			}
		}

		private double RowHeightOfIndex(int index)
		{
			if (index > -1 && index < this.m_RowHeightList.Count)
			{
				return this.m_RowHeightList[index];
			}
			return 0.0;
		}

		private double ColWidthOfIndex(int index)
		{
			if (index > -1 && index < this.m_ColWidthList.Count)
			{
				return this.m_ColWidthList[index];
			}
			return 0.0;
		}

		private TableHead._Tag_HeadType m_TableHeadType = TableHead._Tag_HeadType.HT_NULL;

		private List<TableHeadCell> m_TableHeadInfos = new List<TableHeadCell>();

		private TableSourceInfo m_TableSourceInfo = new TableSourceInfo();

		private int m_RowSize;

		private int m_ColumnSize;

		private List<double> m_RowHeightList = new List<double>();

		private List<double> m_ColWidthList = new List<double>();

		public enum _Tag_HeadType
		{
			HT_NULL = -1,
			HT_FAMILY,
			HT_EXCEL
		}
	}
}
